import { Component, OnInit, Inject} from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { UtilityService} from '../../../../../../service/utils.service';
import {appConfig} from '../../../../../../service/common';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import { WorkitemModule } from '../../../../../../service/delivent/workItemModule';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { ActivatedRoute} from '@angular/router';
import * as _ from 'lodash';
import * as moment from 'moment';



@Component({
  selector: 'app-worklife',
  templateUrl: './worklife.component.html',
   styleUrls: ['./worklife.component.less']
})
export class WorklifeComponent implements OnInit {

    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        private modal: NzModalService,
        public activatedRoute: ActivatedRoute,
        private nznot: NzNotificationService,
        @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
         
    ) { }

    current: number; // 步骤条个数，根据请求回来的数组length决定
    workGuid: string; // 工作项guid
    token:any;


    ngOnInit() {
          this.token  = this.tokenService.get().seniortoken; // 绑定token
        this.workGuid = this.activatedRoute.snapshot.params.id; // 拿到父组件传过来的操作员的guid来进行操作

        this.getData();
    }

   
    lifecycle:any[];
    isSpinning = true;
    getData(){
       this.isSpinning = true;
      let url='/sWorkitem/'+this.workGuid+'/general'
        this.utilityService.getData(appConfig.testUrl  + url)
            .subscribe(
                (val) => {
                    this.isSpinning = false;
                    this.lifecycle = val.result.lifecycle;            
                    this.lifecycle.forEach((i,index)=>{
                        if(i.status == 'Y'){
                            this.current = index;
                        }
                        if(i.time !== ''){
                             i.time = moment(i.time).format('YYYY-MM-DD'); 
                        }
                    })
        },(error) => {    
                  
                    this.nznot.create('error', error.code , error.msg);
                });
  }
}
